<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title th:text="${shop.name+'-退货管理'}"></title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 160px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }

        .T-result {
            margin-bottom: 0;
        }

        .T-result em {
            color: #c33;
            font-style: normal;
        }
    </style>

        <div class="layui-tab layui-tab-brief" lay-filter="demo">
            <ul class="layui-tab-title">
                <li><a th:href="@{/douyin/dashboard(shopId=${shopId})}">首页</a></li>
                <li ><a th:href="@{/douyin/order_list(shopId=${shopId})}">订单管理</a></li>
                <li><a class="layui-this" th:href="@{/douyin/refund_list(shopId=${shopId})}">退货管理</a></li>
                <li><a target="_blank" th:href="@{/douyin/order_print_list(shopId=${shopId},print=0)}" style="color: #eb7350;">打单工具</a></li>
                <li><a href="/shop/shop_list_dy" style="color: #9F9F9F;font-size:small;">选择店铺</a></li>
            </ul>
        </div>

    <!-- content starts -->
<!--    <blockquote class="layui-elem-quote">售后订单</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/douyin/refund_list">
                <input type="hidden" th:value="${shop.getId()}" name="shopId"/>
                <div class="layui-form-item">
                   <!-- <div class="layui-inline">
                        <input type="text" name="refundNum" placeholder="退货编号" class="layui-input">
                    </div>-->
                    <div class="layui-inline">
                        <input id="orderNum" type="text" name="orderNum" placeholder="订单编号" th:value="${orderNum}" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="logisticsCode" placeholder="退货物流单号" th:value="${logisticsCode}" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">申请时间</label>
                        <div class="layui-input-inline" style="width: 120px">
                            <input type="text" class="layui-input" name="startTime" id="startTime" autocomplete="off" placeholder="yyyy-MM-dd" >
                        </div>
                        <div class="layui-input-inline" style="width: 120px">
                            <input type="text" class="layui-input" name="endTime" id="endTime" autocomplete="off" placeholder="yyyy-MM-dd" >
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 100px">

                        <select name="aftersaleType" id="aftersaleType">
                            <option value="">退货类型</option>
                            <option th:each="s:${T(com.b2c.entity.enums.third.EnumDouYinOrderRefundTypeStatus).values()}" th:text="${s.getName()}" th:value="${s.getIndex()}" >售后状态</option>
                        </select>
                    </div>
                    <div class="layui-inline" style="width: 100px">
                            <select name="status" id="status">
                                <option value="">退货状态</option>
                                <option th:each="s:${T(com.b2c.entity.enums.third.EnumDouYinOrderRefundStatus).values()}" th:text="${s.getName()}" th:value="${s.getIndex()}" >售后状态</option>
                            </select>

                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                    <div class="layui-inline">
                        <span id="upd_order" class="layui-btn layui-btn-normal" th:attr="shopId=${shop.getId()}">更新退货订单</span>
                        <span id="upd_order_" style="display: none;" class="layui-btn layui-btn-disabled"><i></i>更新中</span>
                    </div>

                </div>



            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th>退款单号</th>
                <th>订单号</th>
                <th>退款商品</th>
                <th>数量</th>
                <th>退款金额</th>
                <th>退货类型</th>
                <th>退货理由</th>
                <th>申请时间</th>
                <th>退货物流</th>
                <th>退货状态</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${list}">
                <td th:text="${item.getAftersaleId()}"></td>
                <td th:text="${item.getOrderId()}"></td>
               
               
                <td >
                    <img th:src="${item.productPic}" style="width: 40px;height: 40px;float: left" >
                    <p style="float: left;padding-left: 10px;">
                        <span th:text="${#strings.abbreviate(item.productName,18)}" th:title="${item.productName}"></span><br/>
                        <span th:text="${item.specDesc}"></span><br/>
                        <span th:text="${item.specCode}"></span>
                    </p>
                </td>
              

                <td>
                    <span th:text="${item.comboNum}"></span>
                </td>

                <td th:text="${item.comboAmount}"></td>
                <td th:text="${T(com.b2c.entity.enums.third.EnumDouYinOrderRefundTypeStatus).getName(item.getAftersaleType())}"></td>
                <td th:text="${item.questionDesc}"></td>
                <td th:text="${item.applyTime}"></td>
                <td>
                    <p th:text="${item.logisticsCompany}"></p>
                    <p th:text="${item.logisticsCode}"></p>
                    <span class="layui-btn layui-btn-xs layui-btn-primary hand_express" th:attr="data-id=${item.id}">修改物流</span>
                </td>
                <td>
                    <p th:text="${T(com.b2c.entity.enums.third.EnumDouYinOrderRefundStatus).getName(item.getRefundStatus())}"></p>
                    <p th:if="${item.getAftersaleType()!=2 && item.getRefundStatus()==11}" th:text="*{item.getAuditStatus()==0} ? '待确认' : '已确认'"></p>
                </td>
                <td class="center">
                    

                    <a th:href="@{/douyin/refund_detail(refundId=${item.getId()},shopId=${shop.getId()})}">查看详情</a>
                    <a class="layui-btn layui-btn-xs layui-btn-normal remark_refund" th:attr="data-id=${item.getId()},shop-id=${shop.getId()}"  style="color: #fff" >添加备注</a>
                    <br />

                    <!-- <a href="javascript:;" th:if="${item.getAftersaleType()!=2 && item.getAuditStatus()==0}" th:attr="data-id=${item.getAftersaleId()},shop-id=${shop.getId()}"  class="douyin_confirm_refund" >同意退款</a> -->
                   <a href="javascript:;" th:attr="data-id=${item.getId()},shop-id=${shop.getId()}" th:if="${item.getRefundStatus()==11 && item.auditStatus==0}" class="confirm_receive layui-btn layui-btn-primary layui-btn-xs">确认签收</a>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>


    <script type="text/template" id="send-goods">
        <div class="T-box">
            <p><span>快递公司</span>
                <select id="send-company">
                    <option value="">请选择快递公司</option>
                    <option th:each="item:${company}" th:value="${item.getCode()}" th:text="${item.getName()}"></option>
                </select>
            </p>
            <p><span>快递单号</span><input type="text" name="express_code"/></p>
            <p><span>发件人地址</span><input type="text" id="logistics_time" name="logistics_time"/></p>
            <p class="T-result"><span>&nbsp;</span><em id="erro"></em></p>
        </div>
    </script>

    <script src="/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>
    <script type="text/javascript">
        layui.use(['laydate','form'], function () {
            var laydate = layui.laydate;
            var form = layui.form;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            laydate.render({
                elem: '#logistics_time'
            });
            
        $(function () {
            var status = '[[${status}]]';
            var aftersaleType = '[[${aftersaleType}]]';
            $("#status").val(status);
            $("#aftersaleType").val(aftersaleType);
            form.render(); //更新全部
            form.render('select'); //刷新select选择框渲染
            //确认签收
            $(".confirm_receive").click(function () {
                var orderId = $(this).attr("data-id");
                var shopId = $(this).attr("shop-id");
                //确认订单iframe层
                layer.open({
                    type: 2,
                    title: '确认签收',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['480px', '650px'],
                    content: '/douyin/order_refund_confirm?refundId='+orderId+"&shopId="+shopId //iframe的url
                });
            });//确认订单end

             // 填写物流
             $('.hand_express').click(function (e) {
                e.stopPropagation();
                e.preventDefault();
                var id = $(this).attr('data-id');
                Tips.confirm({
                    title: '手动填写物流信息',
                    content: $('#send-goods').html(),
                    define: function () {
                        var data = {
                            id: id,
                            company: $("#send-company  option:selected").text(),
                            companyCode: $("#send-company  option:selected").val(),
                            code: $("input[name='express_code']").val(),
                            logisticsTime: $("input[name='logistics_time']").val()
                        };
                        $.ajax({
                            url: "/ajax_douyin/edit_refund_logistics_code",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    Tips.alert(res.msg);
                                }
                            }
                        });
                    }
                });
            });


            // //退货备注
            // $(".remark_refund").click(function () {
            //     var orderId = $(this).attr("data-id");
            //     var shopId = $(this).attr("shop-id");
            //     //确认订单iframe层
            //     layer.open({
            //         type: 2,
            //         title: '订单确认',
            //         shadeClose: true,
            //         shade: 0.8,
            //         area: ['480px', '650px'],
            //         content: '/douyin/order_refund_confirm?refundId='+orderId+"&shopId="+shopId //iframe的url
            //     });
            // });//退货备注end

            $(".douyin_confirm_refund").click(function () {
                var id = $(this).attr("data-id");
                var shopId = $(this).attr("shop-id");
                var data = {id:id, shopId:shopId};
                //确认订单iframe层
                $.ajax({
                    url: "/ajax_douyin/returnGoodsToWareHouseSuccess",
                    type: "POST",
                    dataType: "JSON",
                    contentType: 'application/json',
                    data:JSON.stringify(data),
                    success: function (res) {
                        alert(res.msg);
                    }
                });
            });

            //更新订单
            $("#upd_order").click(function () {
                $("#upd_order").hide();
                $("#upd_order_").show();
                var startTime = $("#startTime").val();
                var endTime = $("#endTime").val();
                var orderNum = $("#orderNum").val();
                var shopId=$(this).attr("shopId");
                var data = {startTime:startTime, endTime:endTime,orderNum:orderNum,shopId:shopId};
                $.ajax({
                    url: "/ajax_douyin/pull_refund_order",
                    type: "POST",
                    dataType: "JSON",
                    contentType: 'application/json',
                    data:JSON.stringify(data),
                    success: function (res) {
                        if (res.code == 0) {
                            alert("更新成功");
                            window.location.reload();
                        }else {
                            alert(res.msg);
                        }
                        $("#upd_order").show();
                        $("#upd_order_").hide();
                    }
                });

            });
        });
        });
    </script>
</div>
</body>
</html>
